package lcy.homework05.lambdaTest;

import java.util.Date;
import java.util.Objects;

/**
 * @ClassName: Person
 * @Description:
 * @author: 李春洋
 * @date: 2024/4/18 16:28
 * @Blog: https://
 */
public class Person implements Comparable<Person>, Cloneable {
    private String name;
    private String identityNo;
    private Date birthDay;

    public Person() {
    }

    public Person(String name, String identityNo, Date birthDay) {
        this.name = name;
        this.identityNo = identityNo;
        this.birthDay = birthDay;
    }

    public String getName() {
        return name;
    }

    public String getIdentityNo() {
        return identityNo;
    }

    public Date getbirthDay() {
        return birthDay;
    }

    //overrides java.lang.Object.equals
    @Override
    public final boolean equals(Object otherObject) {
        if (this == otherObject)
            return true;
        if (otherObject == null)
            return false;
        if (!(otherObject instanceof Person))
            return false;
        Person other = (Person) otherObject;
        return Objects.equals(this.name, other.name) && Objects.equals(this.identityNo, other.identityNo) && Objects.equals(this.birthDay, other.birthDay);
    }

    //overrides java.lang.Object.hashCode
    @Override
    public final int hashCode() {
        return Objects.hash(name, identityNo, birthDay);
    }

    //overrides java.lang.Object.toString
    @Override
    public String toString() {
        return getClass().getName() + "[name=" + name + "identityNo=" + identityNo + "birthDay= "+birthDay+"]";
    }

    @Override
    public int compareTo(Person other) {
        return this.name.compareTo(other.name);
    }

    @Override
    public Person clone() {
        try {
            Person cloned = (Person) super.clone();
            // Deep copy for birthDay
            if (this.birthDay != null) {
                cloned.birthDay = (Date) this.birthDay.clone();
            }
            return cloned;
        } catch (CloneNotSupportedException e) {
            // This should never happen since we implement Cloneable
            throw new InternalError(e);
        }
    }
}
